<?php
/**
 * @package mikrokosmos
 * mk classes wrappers file created on 2-gen-2005
 * jaco_at_pixeldump_dot_org
 */

if(!class_exists("MKTagHeader")){ class MKTagHeader {}}


 /**
 * generic and very xperimental:
 * converts an image to a swf
 */
function image2swf($imagePath){

	$ext = substr($imagePath, -3);
	$bitmapType = IMAGE_LOSSLESS;

	if($ext == "jpg") $bitmapType = JPEG2;

	$bs = getimagesize($imagePath);

	$swfFileName = substr(basename($imagePath), 0, -3) ."swf";
	$swfVersion = SWF_DEFAULT_VERSION;
	$stageWidth = $bs[0];
	$stageHeight = $bs[1];
	$fps = SWF_DEFAULT_FPS;
	$frameCount = 1;
	$backgroundColor = SWF_DEFAULT_BACKGROUNDCOLOR;
	$iscompressed = "no";

	$swf = new mk_swf($swfFileName,
					$swfVersion,
					$stageWidth,
					$stageHeight,
					$fps,
					$frameCount,
					$backgroundColor,
					$iscompressed);

	$bitmapID = 1;

	if($ext == "jpg") $bmTag = write_bitmapTag_jpeg($bitmapType, $bitmapID, $imagePath);
	else if($ext == "png") $bmTag = write_bitmapTag_png($bitmapID, $imagePath);

	$shapeID = 2;
	$shapeTag = create_bitmap_shapeTag($shapeID, $bitmapID, $stageWidth, $stageHeight);

	$swf->add_tag($bmTag);
	$swf->add_tag($shapeTag);
	$swf->add_tag(swf_placeObject2($shapeID));
	$swf->swf_output();

	//
	$si = fopen(SERVER_MKTMP .$swfFileName, "rb");
	$strout = fread($si, filesize(SERVER_MKTMP .$swfFileName));
	fclose($si);

    header("Content-type: application/x-shockwave-flash");
	echo $swf->get_swfData();
}


 /**
 * generic and very xperimental:
 * converts an image to binary tag
 */
function image2tag($imagePath, $bitmapID = 1, $x = 0, $y = 0){

	$tagData = "";
	$shapeID = $bitmapID + 1;
	$bm = new BitmapItem($bitmapID);

	$bitmapTag = $bm->create_from_file($imagePath);

	$tagData = swf_word($shapeID);

	/*
	global $swfTagList;
	// in this section we build defineshape tag
	$bmShapeTag = swf_word($shapeID);

	$bmShapeTag .= swf_rect($x, $y, $bitmapWidth, $bitmapHeight); // rect structure for defineshape

	//SHAPEWITHSTYLE
	$bmShapeTag .= chr(0x01); // 1 fillstylecount
	$bmShapeTag .= chr(0x41); // clipped bitmap fill

	$bmShapeTag .= swf_word($bitmapID);

	//	MATRIX
	$bmShapeTag .= chr(0xd9);
	$bmShapeTag .= chr(0x40);
	$bmShapeTag .= chr(0x00);
	$bmShapeTag .= chr(0x05);
	$bmShapeTag .= chr(0x00);
	$bmShapeTag .= chr(0x00);
	$bmShapeTag .= chr(0x00);

	$bmShapeTag .= chr(0x00); // no linestyle array
	$bmShapeTag .= chr(0x10); //

	$bmShapeTag .= swf_shape_record_rect($x, $y, $bitmapWidth, $bitmapHeight);

	$strdsSize = strlen($bmShapeTag);

	$bmShapeHead = swf_tag_long_header($swfTagList["DefineShape"], $strdsSize);

	return $bmShapeHead .$bmShapeTag;
	 */

	return $tagData;
}

?>
